package com.wenjie.redHat.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wenjie.redHat.dao.ProductMapper;
import com.wenjie.redHat.domain.entity.ProductCategoryEntity;
import com.wenjie.redHat.domain.entity.ProductEntity;
import com.wenjie.redHat.service.ProductInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Service
@Slf4j
public class ProductInfoServiceImpl extends ServiceImpl<ProductMapper, ProductEntity> implements ProductInfoService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public String updateProduct(ProductEntity productEntity) {
        log.info("====>"+productEntity);
        ProductEntity productInfoEntity=getOne(new QueryWrapper<ProductEntity>()
                .eq("id",productEntity.getId()));
        if (!ObjectUtils.isEmpty(productInfoEntity)){
            this.updateById(productEntity);
        }
        else {
            return "修改失败";
        }
        return "修改成功";
    }

    @Override
    public List<ProductEntity> getByCid(Integer cid) {
        LambdaQueryWrapper<ProductEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProductEntity::getCid,cid);
        List<ProductEntity> productEntities = productMapper.selectList(lambdaQueryWrapper);
        return productEntities;
    }

}
